package roborally;

import java.util.ArrayList;

import Exceptions.IllegalCoordinateException;
/**
 * @author Jef Keijers/Bachelor of Science: Informatics
 * @version 1.0
 */
public class Path {

	public Path (Position current, Position goal,Board board) throws IllegalCoordinateException {	
		calculatePath(current,goal,board);
	}
	
	public ArrayList<Position> getPath() {
		return path;
	}
	
	public void calculatePath(Position current, Position goal,Board board) throws IllegalCoordinateException {
		current = current.copy(board);
		
		path.add(current.copy(board));
		
		while (current.getX() != goal.getX()) {
			 current.setX(current.getX()+sign(goal.getX()-current.getX()),board);
			 path.add(current.copy(board));
		 }
		 
		 while (current.getY() != goal.getY()) {
			 current.setY(current.getY()+sign(goal.getY()-current.getY()),board);
			 path.add(current.copy(board));
		 }
	}
	
	private ArrayList<Position> path=new ArrayList<Position>();
	
	public long sign(long difference) {
		if (difference>0)
			return 1;
		else if (difference <0)
			return -1;
		else
			return 0;	
	}

}
